#ifndef __CARDH__
#define __CARDH__
#include "DataStructureH/attributes.h"
#include "baseactor.h"
#include "component.h"
#include "drawer.h"
#include "enum.h"
#include "updater.h"

class Card;

class ScreenBuffer_t;
struct CardAttr : BaseAttr
{
    // Coord pos,size
    CardAttr() {}
    CardAttr(const Coord_t& pos, const Coord_t& size, const String_t& title, const String_t& con, char border,
             char fill)
        : BaseAttr(pos), size(size), title(title), content(con), border(border), background(fill), offset(1, 0)
    {
        // printf("CardAttr:\ntitle:%s\n content:%s\n border:%c\n fill:%c\n\n", title.data(), con.data(), border, fill);
    }
    Coord_t size;
    Coord_t offset;
    String_t title;
    String_t content;
    char border{'X'};
    char background{'X'};
    bool operator==(const CardAttr& b)
    {
        return (b.pos == this->pos) + (b.size == this->pos) + (b.title == this->title) + (b.content == this->content) +
               (b.border == this->border) + (b.background == this->background) + (b.offset == this->offset);
    }
    // ScreenBuffer_t* basebuffer;
};

struct CardUpdaterInterface
{
  protected:
    using CardUDIF = CardUpdaterInterface;
    CardUpdaterInterface() {}
    ~CardUpdaterInterface() {}

    Card* base;

  public:
    virtual CardUDIF& Position(Coord_t pos) = 0;
    virtual CardUDIF& Size(Coord_t size) = 0;
    virtual CardUDIF& Title(String_t& str) = 0;
    virtual CardUDIF& Content(String_t& str) = 0;
    virtual CardUDIF& BorderStyle(char c) = 0;
    virtual CardUDIF& FillStyle(char c) = 0;
    virtual CardUDIF& Offset(Coord_t offset) = 0;
    virtual Action_t Commit() = 0;
    virtual Action_t Rollback() = 0;
};

class Card : public Component, CardUpdaterInterface // TODO: Try to ":,CardAttr()" next time;
{
    friend class Updater;
    // friend class ScreenBuffer_t;
    //  friend Card& Updater::operator()(class Card* ptr_Card);
    using CardUDIF = CardUpdaterInterface;

  public:
    Card();
    Card(CardAttr);
    Card(Coord_t pos, Coord_t size, const String_t& title, const String_t& con, char border, char fill);
    Card(Coord_t pos, Coord_t size, const String_t& title, const String_t& con, char border, char fill, Drawer* ptr);
    ~Card();

    void render() override;
    void bindDrawer(Drawer* ptr_drawer) override;
    virtual void UpdateChildCoord(Component*, Component*, Component*, Component*) override;

    Action_t Commit() override;
    Action_t Rollback() override;
    Action_t SetFather(Containor*) override;
    Action_t Zerolize() override;

    CardUDIF& Position(Coord_t pos) override;
    CardUDIF& Size(Coord_t size) override;
    CardUDIF& Title(String_t& str) override;
    CardUDIF& Content(String_t& str) override;
    CardUDIF& BorderStyle(char c) override;
    CardUDIF& FillStyle(char c) override;
    CardUDIF& Offset(Coord_t offset) override;

  private:
    CardAttr attribute;
    CardAttr buffer;
    bool NoBackGround;
    // Coord_t offset;

    // ShapeAttr _tempShape;

    // TextAttr _tempTitle;
    // TextAttr _tempContent;
};

#else
#endif